const path = require('path');
const { spawnSync } = require('child_process');


class MyBeforeCompilePlugin {
  apply(compiler) {
    compiler.hooks.beforeCompile.tapAsync('beforeCompile', (params, callback) => {
      const scriptPath = path.resolve(__dirname, 'beforeCompileScript.js');
      const result = spawnSync('node', [scriptPath]);
      if (result.error) {
        console.error('运行脚本时出错:', result.error);
      } else {
        console.log('beforeCompile 脚本运行成功！');
      }
      callback()
    });
  }
}
module.exports = {
  webpack: {
    plugins: [
      new MyBeforeCompilePlugin()
    ],
    alias: {
      '@': path.resolve(__dirname, 'src')
    },
  },
  devServer: {
    port: 8080,
  },
};